/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package nju.bishe.weibo;

import nju.bishe.weibo.data.OAuthConstant;
import weibo4andriod.Weibo;
import weibo4andriod.WeiboException;
import weibo4andriod.http.RequestToken;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

/**
 * 
 * @author longwei.wu modified by gerald.xv at gmail.com
 * 
 */
public class FirstLoginActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.empty);
        new AlertDialog.Builder(this)
        .setIcon(R.drawable.icon)
        .setTitle("这是您是第一次登陆，只需要进行简单的授权，您就可以正常使用啦:)")
        .setPositiveButton("登陆", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
                System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
                Weibo weibo = OAuthConstant.getInstance().getWeibo();
                RequestToken requestToken;
                try {
                    requestToken =weibo.getOAuthRequestToken("bishe://OAuthActivity");
                    Uri uri = Uri.parse(requestToken.getAuthenticationURL());
                    OAuthConstant.getInstance().setRequestToken(requestToken);
                    dialog.dismiss();
                    startActivity(new Intent(Intent.ACTION_VIEW, uri));
                } catch (WeiboException e) {
                    e.printStackTrace();
                }
                 
            }
        }).show();
    }
}
